﻿using System.Linq;
using Loki.Bot;
using Loki.Game.Objects;

namespace toNyxPhysRanger
{
    public class Utilities
    {

        #region Utilities

        public static bool HasAura(Actor actor, string auraName, int minCharges = -1, double minSecondsLeft = -1)
        {
            Aura aura = actor.Auras.FirstOrDefault(a => a.Name == auraName || a.InternalName == auraName);

            // The actor doesn't even have the aura, so we don't need to go messing with it. :)
            if (aura == null)
                return false;

            // Check if mincharges needs to be ensured
            if (minCharges != -1)
            {
                // This is an exclusive check. So if we pass 3, we want to ensure we have 3 charges up.
                // Thus; 2 < 3, we don't have enough charges, and therefore we "don't have the aura" yet
                if (aura.Charges < minCharges)
                    return false;
            }

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (minSecondsLeft != -1)
            // ReSharper restore CompareOfFloatsByEqualityOperator
            {
                if (aura.TimeLeft.TotalSeconds < minSecondsLeft)
                    return false;
            }

            // We have the aura.
            // We have enough charges.
            // And the time left is above the min seconds threshold.
            return true;
        }

        public static bool NumberOfMobsNear(NetworkObject monster, float distance, int count)
        {
            if (monster == null)
                return false;

            int curCount = Targeting.Combat.Targets.OfType<Monster>().Count(mob => mob.Id != monster.Id && mob.Position.Distance(monster.Position) < distance);

            return curCount >= count;
        }

        #endregion

    }
}
